<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></meta>
<title>部分留言管理</title>
</head>
<body>
	<h3>搜索到的留言列表</h3>
	<input type="button" onclick="window.location.href='index.php'"
		value="返回首页"></input>
	<br />
	<br />
<?php
// if (! isset($_POST['submit'])) {
// exit('非法访问!');
// }
require ("./conn.php");
require ("./config.php");
if (get_magic_quotes_gpc()) {
    $ns = htmlspecialchars(trim($_POST['namesearch']));
    $cs = htmlspecialchars(trim($_POST['contentsearch']));
} else {
    $ns = addslashes(htmlspecialchars(trim($_POST['namesearch'])));
    $cs = addslashes(htmlspecialchars(trim($_POST['contentsearch'])));
}
$p = $_GET['p'] ? $_GET['p'] : 1;
$offset = ($p - 1) * $pagesize;
$query_sql = "SELECT * FROM msg WHERE `nickname` LIKE '%$ns%' AND `content` LIKE '%$cs%' ORDER BY id DESC LIMIT  $offset , $pagesize";
$result = mysqli_query($conn, $query_sql);
if (! $result)
    exit('查询数据错误：' . mysqli_error());

// 循环输出当前页显示数据
while (($gb_array = mysqli_fetch_array($result)) != false) {
    echo $gb_array['nickname'], '&nbsp;';
    echo '发表于：', date("Y-m-d H:i:s", $gb_array['createtime']);
    echo ' ID号：', $gb_array['id'], '<br />';
    echo '内容：', nl2br($gb_array['content']), '<br />';
    if (! empty($gb_array['replytime'])) {
        echo '----------------------------<br />';
        echo '最后修改于：', date("Y-m-d H:i:s", $gb_array['replytime']), '<br />';
        echo nl2br($gb_array['reply']), '<br /><br />';
    }
    ?>
<div id="reply">
		<form id="form1" name="form1" method="post" action="reply.php">
			<p>
				<label for="reply">修改本条留言:</label>
			</p>
			<textarea id="reply" name="reply" cols="40" rows="5"><?=$gb_array['reply']?></textarea>
			<p>
				<input name="id" type="hidden" value="<?=$gb_array['id']?>" /> <input
					type="submit" name="submit" value="修改留言" /> <a
					href="reply.php?action=delete&id=<?=$gb_array['id']?>">删除留言</a>
			</p>
		</form>
	</div>
<?php
    echo "<hr />";
}
// 计算留言页数
$count_result = mysqli_query($conn, "SELECT count(*) FROM msg WHERE `nickname` LIKE '%$ns%' AND `content` LIKE '%$cs%'");
$count_array = mysqli_fetch_array($count_result);
$pagenum = ceil($count_array['count(*)'] / $pagesize);
echo '共 ', $count_array['count(*)'], ' 条留言';
if ($pagenum > 1) {
    for ($i = 1; $i <= $pagenum; $i ++) {
        if ($i == $p) {
            echo '&nbsp;[', $i, ']';
        } else {
            echo '&nbsp;<a href="admin.php?p=', $i, '">' . $i . '</a>';
        }
    }
}
?>
<br />
	<br />
<h3>搜索的关键字是</h3>
	<input type="button" onclick="window.location.href='admin.php'"
		value="返回"></input>&nbsp;&nbsp;&nbsp;
	<form action="delsearch.php" method="post">
		<br />昵称：<input type="text" name="namesearch" value="<?php echo $ns?>" />
		<br /> <br />内容：<input type="text" name="contentsearch"
			value="<?php echo $cs?>" /> <br /> <br />
		<button name="delsearch" type="submit">清空这些留言板</button>
	</form>
</body>
</html>